package com.dms.modules.merchant.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dms.common.api.ApiResponse;
import com.dms.modules.merchant.dto.ShopQueryDTO;
import com.dms.modules.merchant.service.MerchantService;
import com.dms.modules.merchant.vo.ShopDisplayVO;
import com.dms.modules.product.vo.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/shops")
@Api(tags = "店铺展示接口")
@Slf4j
public class ShopDisplayController {

    @Autowired
    private MerchantService merchantService;
    
    @GetMapping("/list")
    @ApiOperation("获取店铺列表")
    public ApiResponse<IPage<ShopDisplayVO>> getShopList(ShopQueryDTO queryDTO) {
        return ApiResponse.success(merchantService.getShopList(queryDTO));
    }
    
    @GetMapping("/{id}")
    @ApiOperation("获取店铺详情")
    public ApiResponse<ShopDisplayVO> getShopDetail(@PathVariable Long id) {
        return ApiResponse.success(merchantService.getShopDetail(id));
    }
    
    @GetMapping("/{id}/products")
    @ApiOperation("获取店铺商品")
    public ApiResponse<IPage<ProductVO>> getShopProducts(
            @PathVariable Long id,
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("分类ID") @RequestParam(required = false) Long categoryId) {
        return ApiResponse.success(merchantService.getShopProducts(id, pageNum, pageSize, categoryId));
    }
    
    @GetMapping("/recommended")
    @ApiOperation("获取推荐店铺")
    public ApiResponse<IPage<ShopDisplayVO>> getRecommendedShops(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize) {
        ShopQueryDTO queryDTO = new ShopQueryDTO();
        queryDTO.setOnlyRecommend(1);
        queryDTO.setPageNum(pageNum);
        queryDTO.setPageSize(pageSize);
        return ApiResponse.success(merchantService.getShopList(queryDTO));
    }
} 